﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyBasicLib.Reflection;
using RUC.Core.Entities;
using MyBasicLib.Reflection.FastReflection.Emit;
namespace MyBasicLib.PerformanceTest
{
    class ReflectionTest
    {

        public static void Run(int count)
        {
            ReflectionTest test = new ReflectionTest();
            Diagnostics.CodeTimer.Initialize();
            test.DirectTest(count);
            test.PrimiteReflectionTest(count);
            test.FastReflectionTest(count);
            test.FastReflectionCacheTest(count);


        }
        
        static System.Reflection.ConstructorInfo info = typeof(App).GetConstructor(Type.EmptyTypes);
        ConstructorInvoker ci = new ConstructorInvoker(info);

        public void FastReflectionTest(int count)
        {
            MyBasicLib.Diagnostics.CodeTimer.Time("FastReflectionTest", count, () => info.FastInvoke());
        }
        public void FastReflectionCacheTest(int count)
        {
            MyBasicLib.Diagnostics.CodeTimer.Time("FastReflectionCacheTest", count, () => ci.Invoke());
        }
        public void PrimiteReflectionTest(int count)
        {
            MyBasicLib.Diagnostics.CodeTimer.Time("PrimiteReflectionTest", count, () => info.Invoke(new object[0]));
        }

        public void DirectTest(int count)
        {
            MyBasicLib.Diagnostics.CodeTimer.Time("DirectTest", count, () => new App());
        }
    }
}
